﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
#if NETFX_CORE
using Windows.ApplicationModel.Resources;

#endif

namespace StyleMVVM.Validation.Impl.Fluent
{
	public class FluentSetValueProvider<T, TValue> : IFluentValueProvider<T>
	{
		private readonly IEnumerable<TValue> values;

		public FluentSetValueProvider(IEnumerable<TValue> values)
		{
			this.values = values;
		}

		public string MessageString
		{
			get
			{
				string returnValue = null;

				foreach (TValue value in values)
				{
					returnValue += value + ", ";
				}

				if (!string.IsNullOrEmpty(returnValue))
				{
					int commaIndex = returnValue.LastIndexOf(", ");

					if (commaIndex > 0)
					{
						returnValue = returnValue.Substring(0, commaIndex);
					}
				}

				return returnValue;
			}
		}

		public Expression GenerateExpression(IFluentExpressionProvider propertyExpressionProvider)
		{
			List<ConstantExpression> constantValues = new List<ConstantExpression>();

			foreach (TValue value in values)
			{
				constantValues.Add(Expression.Constant(value));
			}

			return Expression.NewArrayInit(typeof(TValue), constantValues);
		}

		public string GenerateDisplayString(ResourceLoader loader)
		{
			return MessageString;
		}
	}
}